// pages/video-detail/index.js
import {
  getVideoDetailData,
  getVideoUrlData,
  getRelativeVideoData
} from '../../services/video-api'

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    mvInfo:{},
    mvUrl:'',
    relativeVideos:[],
    screenHeight:0
  },
  onLoad: function (options) {
    const {id} = options
    const screenHeight = app.globalData.screenHeight
    this.setData({screenHeight})
    this.getPageData(id)
  },
  getPageData(id){
    this.setData({id})
    getVideoUrlData(id).then(res => {
      const mvUrl = res.data.url 
      this.setData({mvUrl})
    })
    getVideoDetailData(id).then(res => {
      const mvInfo = res.data 
      this.setData({mvInfo})
      wx.setNavigationBarTitle({
        title: mvInfo.name,
      })
    })
    getRelativeVideoData(id).then(res => {
      const relativeVideos = res.mvs
      this.setData({relativeVideos})
    })
  },
  goToMvDetail(event){
    const id = event.currentTarget.dataset.id
    this.getPageData(id)
  }
 

})